<template>
<div class="about">
  <!-- 面包屑导航 -->
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>协会信息</el-breadcrumb-item>
  </el-breadcrumb>
  <setUp title="协会信息">
    <div style="margin: 0 auto;">
      <el-form :label-position="labelPosition" label-width="150px" :model="formLabelAlign" style="display:flex;width:1200px;flex-wrap:wrap">
        <my-input label="名称" v-model="formLabelAlign.name" prop="name" required></my-input>
        <my-input label="法人" v-model="formLabelAlign.legalPerson" prop="legalPerson" required></my-input>
        <my-input label="办公地址" v-model="formLabelAlign.officeAddress" prop="officeAddress" required></my-input>
        <my-input label="联系人" v-model="formLabelAlign.contactPerson" prop="contactPerson" required></my-input>
        <my-input label="联系电话" v-model="formLabelAlign.contactMobile" prop="contactMobile" required mobile></my-input>
        <my-input label="邮箱" v-model="formLabelAlign.email" prop="email" required email></my-input>
        <myFormItem label="资质文件" required>
          <el-upload class="upload-demo" style="width: 220px" action="https://jsonplaceholder.typicode.com/posts/" :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" multiple :limit="3" :on-exceed="handleExceed" :file-list="fileList">
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
          </el-upload>
        </myFormItem>
        <myFormItem label="协会logo" required>
          <el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/" :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
            <img v-if="imageUrl" :src="imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </myFormItem>
      </el-form>
      <div style="margin:50px auto;width:200px;">
        <el-button class="submit-btn" type="primary" @click="">修改信息</el-button>
      </div>
    </div>
  </setUp>
</div>
</template>

<script>
import {
  createNamespacedHelpers
} from "vuex";
const {
  mapState,
  mapActions
} = createNamespacedHelpers("user");
export default {
  data() {
    return {
      imageUrl: '',
      fileList: [{
        name: 'food.jpeg',
        url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
      }, {
        name: 'food2.jpeg',
        url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
      }],
      labelPosition: "right",
      formLabelAlign: {},
    };
  },
  computed: {
    ...mapState({
      user_id: (state) => state.userId,
      user_name: (state) => state.name,
      user_role: (state) => state.roles,
    }),
  },
  methods: {
    // 上传照片
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 2;
      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    },
    // 上传文件
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${ file.name }？`);
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/ .avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

/deep/ .avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 120px;
  height: 120px;
  line-height: 120px;
  text-align: center;
}

.avatar {
  width: 120px;
  height: 120px;
  display: block;
}
</style>
